前言
建立案子所需的環境,將安裝的過程整理成筆記
Platform
- Linux Ubuntu 20.04 amd64 (virt-manager)
為了符合 案子 所需的環境,所以我們使用 docker
Install Docker
# SET UP THE REPOSITORY
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# INSTALL DOCKER
sudo apt install docker.io
Using docker without sudo
sudo setfacl -m user:$USER:rw /var/run/docker.sock
Docker Pull
接下來我們需要一個 pytorch 的環境,所以我在 docker hub 上找到了 這個
我選擇了 latest 的版本作為本次的開發環境
# 指令
docker pull name@digest
Example:
docker pull pytorch/pytorch:latest@sha256:1e26efd426b0fecbfe7cf3d3ae5003fada6ac5a76eddc1e042857f5d049605ee
查看 docker images
docker images
output:
REPOSITORY TAG IMAGE ID CREATED SIZE
pytorch/pytorch <none> 71eb2d092138 5 weeks ago 9.96GB
我們需要 IMAGE ID
Run docker
docker run -it [IMAGE ID]
Example:
docker run -it 71eb2d092138
如果成功,你就會看到你的 bash prompt 變成 root 開頭
查看目前啟動的 docker container
開啟一個新的 Terminal 並執行以下指令
docker ps
複製本機檔案到 docker container
指令
docker cp file_path [IMAGE ID]:file_path
在 Docker Container 上安裝 git
apt update
apt install git
Commit docker image
docker commit <containerID> <repository>:<tag>
Example:
docker commit 3d555451f07a mymatlab:r2020a
之後可以再次用 docker ps
看看是否有多一個 docker image
使用 docker run -it [IMAGE ID]
就可以從上次的 commit 開始工作了
Export Docker Image
完成工作之後就可以將 docker image 打包送給別人了
# Export docker image
docker save myusername/myproject:latest | gzip -c > myproject_img_bak20141103.tgz
# Load docker image
gunzip -c myproject_img_bak20141103.tgz | docker load
Resources
- https://ithelp.ithome.com.tw/articles/10239123
- https://registry.hub.docker.com/layers/pytorch/pytorch/latest/images/sha256-1e26efd426b0fecbfe7cf3d3ae5003fada6ac5a76eddc1e042857f5d049605ee?context=explore
- https://registry.hub.docker.com/layers/pytorch/pytorch/latest/images/sha256-1e26efd426b0fecbfe7cf3d3ae5003fada6ac5a76eddc1e042857f5d049605ee?context=explore